/**
 * 2025/01/01 - 2025/12/31
 */
package com.snail.server.database.engine.ddl.field.enums;

import com.baomidou.mybatisplus.annotation.IEnum;
import com.snail.server.database.engine.ddl.field.annotation.ToFieldType;
import com.snail.starter.commons.error.CommonErrorCode;
import com.snail.starter.commons.exception.BizException;
import com.snail.server.database.engine.error.DatabaseEngineErrorCode;
import lombok.Getter;
import lombok.ToString;

import java.util.Arrays;

/**
 * @author zgadmin
 * @date 2025/8/28 16:32
 */
@Getter
@ToString
public enum FieldTypeEnum implements IEnum<String> {

    TEXT("text", "文本"),
    LONG_TEXT("long_text", "长文本"),
    INT("int", "整型"),
    BIGINT("bigint", "长整型"),
    DOUBLE("double", "浮点型"),
    DATETIME("data_time", "日期类型"),
    OTHER("other", "其他类型"),
    ;

    private final String value;

    private final String desc;

    FieldTypeEnum(String value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    @ToFieldType
    public static FieldTypeEnum getEnum(String value) {
        if (null == value || "".equals(value)) {
            throw BizException.of(CommonErrorCode.MISS_PARAM_ERROR, new Object[]{"field type"});
        }
        return Arrays.stream(values()).filter(e -> e.getValue().equals(value)).findFirst().orElseThrow(() -> BizException.of(DatabaseEngineErrorCode.NOT_SUPPORT_FIELD_TYPE, new Object[]{value}));
    }
}